#ifndef __SW64_PAL_H
#define __SW64_PAL_H

#define HMC_cpuid		0x03
#define HMC_ret			0x1A
#define HMC_swpipl		0x35

#define GET_CPU_FREQ            4

#define __CALL_HMC_W1(NAME, TYPE0)					\
static inline void NAME(TYPE0 arg0)					\
{									\
  register TYPE0 __r16 __asm__("$16") = arg0;				\
  __asm__ __volatile__ ("sys_call %1 # "#NAME				\
			: "=r"(__r16)					\
			: "i"(HMC_ ## NAME), "0"(__r16)			\
			: "$1", "$22", "$23", "$24", "$25");		\
}

#define __CALL_HMC_RW1(NAME, RTYPE, TYPE0)				\
static inline RTYPE NAME(TYPE0 arg0)					\
{									\
  register RTYPE __r0 __asm__("$0");					\
  register TYPE0 __r16 __asm__("$16") = arg0;				\
  __asm__ __volatile__ ("sys_call %2 # "#NAME				\
			: "=r"(__r16), "=r"(__r0)			\
			: "i"(HMC_ ## NAME), "0"(__r16)			\
			: "$1", "$22", "$23", "$24", "$25");		\
  return __r0;								\
}

#define __CALL_HMC_RW2(NAME, RTYPE, TYPE0, TYPE1)			\
static inline RTYPE NAME(TYPE0 arg0, TYPE1 arg1)			\
{									\
  register RTYPE __r0 __asm__("$0");					\
  register TYPE0 __r16 __asm__("$16") = arg0;				\
  register TYPE1 __r17 __asm__("$17") = arg1;				\
  __asm__ __volatile__ ("sys_call %3 # "#NAME				\
			: "=r"(__r16), "=r"(__r17), "=r"(__r0)		\
			: "i"(HMC_ ## NAME), "0"(__r16), "1"(__r17)     \
			: "$1", "$22", "$23", "$24", "$25");            \
  return __r0;								\
}

__CALL_HMC_W1(ret, unsigned long);
__CALL_HMC_RW1(swpipl, unsigned long, unsigned long);
__CALL_HMC_RW2(cpuid, unsigned long, unsigned long, unsigned long);

#endif /* __SW_64_HMC_H */
